<template>
  <div class="user-detail">
    <el-form
      label-position="right"
      label-width="80px"
      :model="formData"
      :rules="rules"
      ref="formData"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="用户名" prop="user_name">
            <el-input size="small" v-model="formData.user_name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="密码" prop="paw">
            <el-input size="small" v-model="formData.paw"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="姓名" prop="name">
            <el-input size="small" v-model="formData.name"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="手机号" prop="phone">
            <el-input size="small" v-model="formData.phone"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="所属部门" prop="department">
            <el-select
              v-model="formData.department"
              placeholder="请选择"
              size="small"
            >
              <el-option
                v-for="item in departmentOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex" justify="end">
        <el-button type="primary" size="small" @click="submitBtn('formData')">
          确定
        </el-button>
      </el-row>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      formData: {},
      rules: {
        user_name: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        paw: [{ required: true, message: "请输入密码", trigger: "blur" }],
        name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        phone: [{ required: true, message: "请输入手机号", trigger: "blur" }],
        department: [
          { required: true, message: "请选择部门", trigger: "change" },
        ],
      },
      departmentOptions: [
        {
          value: "yunweizhongxin",
          label: "运维中心",
        },
        {
          value: "zonghebu",
          label: "综合部",
        },
        {
          value: "caiwubu",
          label: "财务部",
        },
        {
          value: "dangqunbu",
          label: "党群部",
        },
      ],
    }
  },
  methods: {
    submitBtn(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!")
        }
      })
    },
  },
}
</script>
